<?php
  session_cache_limiter('private,must-revalide');
   /**
   * 处理上传页面
   */ 
  if ($_POST['btn_sub'])
  {
    $cate_id = 0; //分类
	//date_default_timezone_set('Asia/Shanghai');
	$time=date('Y-m-d');
	$time1=date('Y-m-d H:i:s');
    $ch_headline = work_str($_POST["ch_headline"], 1);		//中文标题
    $search = "SELECT * FROM $TBL_NEWS WHERE ch_headline='$ch_headline'";
	$result = mysql_query( $search );
	if( @mysql_num_rows( $result ) > 0 )
	{
		MyNotice("該標題命名活動已存在,請換個標題試試！");
		exit();
	}
   	$ch_text = work_str($_POST["chinese_edit"], 1);				//中文内容	
	$ch_source= work_str($_POST['ch_source'],1);				//中文来源
	$en_headline = work_str($_POST["en_headline"], 1);			//英文标题
	$en_text = work_str($_POST["english_edit"], 1);					//中英内容
	$en_source = work_str($_POST["en_source"], 1);			    //英文来源
	$cont1 = array("<p>","</p>");
	$cont2 = array("","</br>");
	$ch_text1 = str_replace($cont1, $cont2, $ch_text);
	$en_text1 = str_replace($cont1, $cont2, $en_text);
	
	$user_id = $_SESSION['user_id'];
	$img = $_FILES['img']['name'];	
	$imgname = explode('.',$img);	
	$count = count($imgname)-1;
	$imgn = time().'.'.$imgname[$count];
    $query = "INSERT INTO $TBL_NEWS SET cate_id='$cate_id',
	ch_headline='$ch_headline',ch_source='$ch_source',ch_text='$ch_text',ch_cate_name='$ch_cate_name',
	en_headline='$en_headline',en_source='$en_source',en_text='$en_text',en_cate_name='$en_cate_name',
	date_added='$time1',date_up ='$time1',user_id='$user_id',img='$imgn',state=1";	
    $res = mysql_query($query) or die(mysql_error());
	$insert_id = mysql_insert_id();	
	/*if($_FILES['img']['name']!='')
	{		
		@mkdir($conf['fck_upload'] . "news/".$insert_id,777);
		@chmod($conf['fck_upload'] . "news/".$insert_id,777);
		@mkdir($conf['fck_upload'] . "news/".$insert_id."/homeimage",777);
		@chmod($conf['fck_upload'] . "news/".$insert_id,"/homeimage",777);	
		$img_file =$conf['fck_upload'] . "news/".$insert_id."/homeimage";
		$file_full = $img_file."/".$imgn;
		$upload_file = $_FILES['img']['tmp_name']; //上传过来的压缩文件
		move_uploaded_file($upload_file, $file_full);       //上传到指定文件夹		
	}
	*/
	/*for($i=0; $i<count($_FILES['upfile']['name']); $i++) 
	{       				  
		$name = $_FILES['upfile']['name'][$i];
		if($name!='')
		{
			@mkdir($conf['fck_upload'] . "news/".$insert_id,777);
			@chmod($conf['fck_upload'] . "news/".$insert_id,777);
			$save_file = $conf['fck_upload'] . "news/".$insert_id;   //存上传文件的文件夹
			$save_path = $save_file;			
			$file_name = $name;	
			$file_full = $save_path .'/'. $file_name; 
			$upload_file = $_FILES['upfile']['tmp_name'][$i]; //上传过来的压缩文件
			move_uploaded_file($upload_file, $file_full);       //上传到指定文件夹
			chmod($file_full,0777);
			$query1="INSERT INTO $TBL_PIC SET NEW_ID='$insert_id',name='$name',type=0,IMG_NAME='$file_name',REG_TIME='$time1'";
			$result1 = mysql_query($query1) or die(mysql_error());
		}
	 
	}*/
		 MyNotice("活動添加成功", 2, "news.php");
		 exit(0);

  } 

  include_once("list_cate.php");
  $time1=date('Y-m-d H:i:s');
  $tpl -> set_file(array("main" => "add_news.htm"));
  $tpl -> set_block("main","TYPE_LIST","type_list");
  //加载FCKeditor编辑器
  include($conf["base_path"] ."fckeditor/fckeditor.php");
  //中文
  $editor = new FCKeditor('chinese_edit');
  $editor -> BasePath   = "../../fckeditor/";
  $editor -> ToolbarSet = "Normal";
  $editor -> Width      = "100%";
  $editor -> Height     = "500";
  $chinese_edit = $editor->CreateHtml();
  //英文
  $editor2 = new FCKeditor('english_edit') ;
  $editor2->BasePath   = "../../fckeditor/";
  $editor2->ToolbarSet = "Normal";
  $editor2->Width      = "100%";
  $editor2->Height     = "500";
  $english_edit = $editor2->CreateHtml();
 
  $tpl -> set_var(array(
                         "SHOW_CATE" => $show_cate,
	     				 "CHINESE_EDIT" => $chinese_edit,
						 "ENGLISH_EDIT" => $english_edit,
						 "TIME" => $time1
                       ));
 
  $tpl->set_var($conf);
  $tpl -> parse("Output", "main");
  $tpl -> p("Output");
  exit(0);
?>